/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ipfms.stripes;

import able.stripes.JSP;
import com.google.inject.Inject;
import ipfms.manager.InboxManager;
import ipfms.model.Inbox;
import ipfms.model.Pengguna;
import ipfms.model.PenggunaPeranan;
import ipfms.stripes.config.AuthRequired;
import ipfms.workflow.WorkflowService;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.stripes.action.Before;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.controller.LifecycleStage;

/**
 *
 * @author fikri
 */
@UrlBinding("/inbox")
@AuthRequired
public class InboxAction extends BaseActionBean{
    
    
    @Inject InboxManager inboxManager;
    
    @Inject WorkflowService workflowService;
    
    private Pengguna pengguna;
    
    private List<Inbox> inboxList;
    
    
    @DefaultHandler
    public Resolution showInbox() {
        
        List<PenggunaPeranan> senaraiPeranan = pengguna.getSenaraiPeranan();
        
        inboxList = new ArrayList<Inbox>();
        
        inboxList = workflowService.queryTasks(pengguna.getIdPengguna(), senaraiPeranan);       
       
        
//        for (PenggunaPeranan penggunaPeranan : senaraiPeranan) {
//            String idWorkflow = penggunaPeranan.getPeranan().getDesc();
//            
//            List<Inbox> tmp = inboxManager.senaraiInbox(idWorkflow, pengguna.getIdPengguna());
//
//            for (Inbox inbox : tmp) {
//                inboxList.add(inbox);
//            }            
//        }                
        
        return new JSP("inbox.jsp");
    }
    
    @Before(stages= LifecycleStage.BindingAndValidation)
    public void rehydrate() {
        pengguna = getContext().getCurrentUser();
    }

    public List<Inbox> getInboxList() {
        return inboxList;
    }

    public void setInboxList(List<Inbox> inboxList) {
        this.inboxList = inboxList;
    }
    
    
}
